﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Farigola.Engine.SystemData.Entity.inst;

namespace Farigola.Engine.TestUnit
{
    [TestFixture]
    public class EntityClassAnonymTestUnit
    {
	    /**
	     * Create a inst Class anonym.
	     * under the root_folder.
	     */
	    [Test]
	    public void testCreateEntInstClassAnonym() {
            Engine engine = EngineCommonTestUnit.CreateInitEngine();
            Workspace wksp = engine.GetWorkspace();
		
		    // create a project
		    Project prj= wksp.CreateActiveProject("prj");

		    // create a inst class anonym
		    EntInstClassAnonym instClassAdr= prj.createEntInstClassAnonym(null, "MyAdr");
		    Assert.IsNotNull(instClassAdr, "The instClass anonym 'MyAdr' should be created.");
				
		    // add inst DM directly
		    EntInstBase instDM  =prj.AddInstClassAnonymDataMember(instClassAdr, "string", "street");
		    Assert.IsNotNull(instDM, "The inst DM 'street' should be created.");
		
		    // get the tool to find entities in the project
		    EntityFinder entFinder= prj.GetEntityFinder();
		
		    // find the type class, by the name, scan recursilvy
		    EntInstClassAnonym entClassAnonymMyAdrFind =entFinder.FindEntInstClassAnonymByName("MyAdr");		
		    Assert.IsNotNull(entClassAnonymMyAdrFind, "The instClass anonym 'MyAdr' should be found.");

		    //--check the DM inst (name, type)
		    // get the DM inst
		    EntInstBase instDMStreet= entFinder.FindEntInstClassDataMemberByName(entClassAnonymMyAdrFind, "street");
		    Assert.IsNotNull(instDMStreet, "The inst DM 'street' should be found.");
		    Assert.AreEqual("street",instDMStreet.GetName(),"The inst DM should be named 'street'.");
	    }
	
	    // under the root folder user, implicite
	
	    // essai de creer 2 champs instDM avec le meme nom->err
	
	    // c'est une instance! -> set value directement sur instDM
    }
}
